def f (x):
    for i in range(2,x):
        if x%i == 0:
            return (0)
    return(x)


x = int(input())
if x<1000 or x>9999:
    print (0)
    exit()

e = x%10
d = (x//10)%10
s = (x//100)%10
t = x//1000

mas=[0]*10
mas[0]=e
mas[1]=s
mas[2]=t
mas[3]=d
mas[4]=t*10+s
mas[5]=s*10+d
mas[6]=d*10+e
mas[7]=t*100+s*10+d
mas[8]=s*100+d*10+e
mas[9]=x

maxi=0
for i in mas:
    t=f(i)
    if t!=0 and t>maxi:
        maxi=t
print(maxi)
